package com.zkjl.protect_business.controller;

import com.zkjl.protect_business.common.ApiResponse;
import com.zkjl.protect_business.dto.ArchiveDTO;
import com.zkjl.protect_business.entity.Archive;
import com.zkjl.protect_business.service.ArchiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = {"存档"})
public class ArchiveConterller {

    @Autowired
    ArchiveService archiveService;

    @ApiOperation(value = "创建存档", notes = "创建存档", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "businesId", value = "业务分类id", required = true, paramType = "path"),
            @ApiImplicitParam(name = "name", value = "存档名称", required = true, paramType = "query")
    })
    @PostMapping(value = "/business/{businesId}/archives")
    public ApiResponse<Archive> create(@PathVariable String businesId,@RequestBody ArchiveDTO archiveDTO) {

        Archive archive = archiveService.create(archiveDTO, businesId);
        return ApiResponse.ofSuccess(archive);

    }

    @ApiOperation(value = "获取业务下的所有存档", notes = "获取业务下的所有存档", httpMethod = "GET")
    @GetMapping(value = "/business/{businesId}/archives")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "businesId", value = "业务分类id", required = true, paramType = "path")
    })
    public ApiResponse<List<Archive>> list(@PathVariable String businesId) {
        List<Archive> list = archiveService.list(businesId);
        return ApiResponse.ofSuccess(list);
    }

    @ApiOperation(value = "删除存档", notes = "删除存档", httpMethod = "DELETE")
    @DeleteMapping(value = "/business/{businesId}/archives/{id}")
    public ApiResponse del(@PathVariable String id) {
        Boolean del = archiveService.del(id);
        return ApiResponse.ofSuccess(del);
    }



}
